package com.jeegit.ecms.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.jeegit.common.core.domain.Ztree;
import com.jeegit.common.utils.DateUtils;
import com.jeegit.common.utils.IdUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jeegit.ecms.mapper.CmsVideoCategoryMapper;
import com.jeegit.ecms.domain.CmsVideoCategory;
import com.jeegit.ecms.service.ICmsVideoCategoryService;
import com.jeegit.ecms.utils.ECMSUtils;
import com.jeegit.common.core.text.Convert;

/**
 * 视频分类Service业务层处理
 * 
 * @author jeegit
 * @date 2022-06-25
 */
@Service
public class CmsVideoCategoryServiceImpl implements ICmsVideoCategoryService 
{
    @Autowired
    private CmsVideoCategoryMapper cmsVideoCategoryMapper;

    /**
     * 查询视频分类
     * 
     * @param id 视频分类主键
     * @return 视频分类
     */
    @Override
    public CmsVideoCategory selectCmsVideoCategoryById(Long id)
    {
        return cmsVideoCategoryMapper.selectCmsVideoCategoryById(id);
    }

    /**
     * 查询视频分类列表
     * 
     * @param cmsVideoCategory 视频分类
     * @return 视频分类
     */
    @Override
    public List<CmsVideoCategory> selectCmsVideoCategoryList(CmsVideoCategory cmsVideoCategory)
    {
        return cmsVideoCategoryMapper.selectCmsVideoCategoryList(cmsVideoCategory);
    }

    /**
     * 新增视频分类
     * 
     * @param cmsVideoCategory 视频分类
     * @return 结果
     */
    @Override
    public int insertCmsVideoCategory(CmsVideoCategory cmsVideoCategory)
    {
    	cmsVideoCategory.setId(IdUtils.getInstance(1l).nextId());
    	cmsVideoCategory.preInsert(cmsVideoCategory);
        cmsVideoCategory.setCreateTime(DateUtils.getNowDate());
        if (cmsVideoCategory.getCmsSiteId()==null) {
        	cmsVideoCategory.setCmsSiteId(ECMSUtils.getDefaultSiteId());
		}
        return cmsVideoCategoryMapper.insertCmsVideoCategory(cmsVideoCategory);
    }

    /**
     * 修改视频分类
     * 
     * @param cmsVideoCategory 视频分类
     * @return 结果
     */
    @Override
    public int updateCmsVideoCategory(CmsVideoCategory cmsVideoCategory)
    {	cmsVideoCategory.preUpdate(cmsVideoCategory);
        return cmsVideoCategoryMapper.updateCmsVideoCategory(cmsVideoCategory);
    }

    /**
     * 批量删除视频分类
     * 
     * @param ids 需要删除的视频分类主键
     * @return 结果
     */
    @Override
    public int deleteCmsVideoCategoryByIds(String ids)
    {
        return cmsVideoCategoryMapper.deleteCmsVideoCategoryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除视频分类信息
     * 
     * @param id 视频分类主键
     * @return 结果
     */
    @Override
    public int deleteCmsVideoCategoryById(Long id)
    {
        return cmsVideoCategoryMapper.deleteCmsVideoCategoryById(id);
    }

    /**
     * 查询视频分类树列表
     * 
     * @return 所有视频分类信息
     */
    @Override
    public List<Ztree> selectCmsVideoCategoryTree()
    {
        List<CmsVideoCategory> cmsVideoCategoryList = cmsVideoCategoryMapper.selectCmsVideoCategoryList(new CmsVideoCategory());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        ztrees=ECMSUtils.addTreeRoot(ztrees);//追加根目录
        for (CmsVideoCategory cmsVideoCategory : cmsVideoCategoryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(cmsVideoCategory.getId());
            ztree.setpId(cmsVideoCategory.getParentId());
            ztree.setName(cmsVideoCategory.getTitle());
            ztree.setTitle(cmsVideoCategory.getTitle());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
